/*
 * Powered By dico
 * Since 2017 - 2018
 */package com.seeyoui.kensite.framework.cms.study.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;

import java.util.*;

import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;
import com.seeyoui.kensite.common.util.*;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.framework.cms.study.domain.Study;
import com.seeyoui.kensite.framework.cms.study.persistence.StudyMapper;

/**
 * Study
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-01-12
 */

@Service
public class StudyService extends BaseService {
	
	@Autowired
	private StudyMapper studyMapper;

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public Study findOne(String id) throws CRUDException{
		return studyMapper.findOne(id);
	}
	
	/**
	 * 查询数据集合
	 * @param study
	 * @return
	 * @throws CRUDException
	 */
	public List<Study> findList(Study study) throws CRUDException {
		return studyMapper.findList(study);
	}
	
	/**
	 * 查询所有数据集合
	 * @param study
	 * @return
	 * @throws CRUDException
	 */
	public List<Study> findAll(Study study) throws CRUDException {
		return studyMapper.findAll(study);
	}
	
	/**
	 * 查询数据总数
	 * @param study
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(Study study) throws CRUDException {
		return studyMapper.findTotal(study);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param study
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(Study study) throws CRUDException {
		return studyMapper.findExTotal(study);
	}
	
	/**
	 * 数据新增
	 * @param study
	 * @throws CRUDException
	 */
	public void save(Study study) throws CRUDException{
		study.preInsert();
		studyMapper.save(study);
	}
	
	/**
	 * 数据修改
	 * @param study
	 * @throws CRUDException
	 */
	public void update(Study study) throws CRUDException{
		study.preUpdate();
		studyMapper.update(study);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		studyMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param study
	 * @throws CRUDException
	 */
	public void remove(Study study) throws CRUDException{
		study.preUpdate();
		studyMapper.remove(study);			
	}
	
	/**
	 * 根据用户id查询学习记录
	 * @param userId
	 * @return
	 * @throws CRUDException
	 */
	public List<Study> findStudyByUserId(String userId) throws CRUDException{
		return studyMapper.findStudyByUserId(userId);
	}
	
	/**
	 * 根据用户id和文章id查询学习记录
	 * @param userId
	 * @param articleId
	 * @return
	 * @throws CRUDException
	 */
	public Study findStudyByUserIdAndArticleId(String userId,String articleId) throws CRUDException{
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("userId", userId);
		map.put("articleId", articleId);
		Study study = studyMapper.findStudyByUserIdAndArticleId(map);
		return study;
	}
	
}